<!--
 * @Author: hq
 * @Date: 2022-05-24 11:33:44
 * @LastEditors: hq
 * @LastEditTime: 2022-07-12 19:15:58
 * @Description: your project
 * @version: 1.0
-->
<template>
  <div>
    <el-tree
      ref="trees"
      :data="treeData"
      :props="defaultProps"
      show-checkbox
      node-key="id"
      :default-checked-keys="current_id"
      :default-expanded-keys="current_id"
      @check="checkClick"
    >
    </el-tree>
  </div>
</template>

<script>
import { menuList } from "@/api/manager";
export default {
  props: ["auth"],
  data() {
    return {
      treeData: [],
      defaultProps: {
        /** 唯一标识 **/
        value: "id",
        /** 标签显示 **/
        label: "title",
        /** 子级 **/
        children: "children",
      },
      current_id: [2, 3],
    };
  },
  methods: {
    async menuList() {
      const { data, err } = await menuList({});
      if (err === 0) {
        this.treeData = data;
        this.current_id = this.auth;
      }
    },
    checkClick(checkedNodes, checkedKey) {
      console.log(checkedKey.checkedKeys);
      this.$emit("selectTree", checkedKey.checkedKeys);
    },
  },
  created() {
    this.menuList();
  },
};
</script>

<style lang="scss" scoped></style>
